package com.resou.reader.dialog.fifteenfree;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.resou.reader.R;
import com.resou.reader.activity.freebook.FreeBookActivity;
import com.resou.reader.base.ResouBaseDialog;
import com.resou.reader.utils.PreferenceUtil;

import butterknife.OnClick;

/**
 * 十五天免费阅读的活动对话框
 */
public class FifteenFreeDialog extends ResouBaseDialog<FifteenFreeContract.Presenter> implements FifteenFreeContract.View {
    public static FifteenFreeDialog newInstance() {
        Bundle args = new Bundle();
        FifteenFreeDialog fragment = new FifteenFreeDialog();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initPresenter() {
        mPresenter = new FifteenFreePresenter(this);
    }

    @Override
    public int getLayoutId() {
        return R.layout.dialog_fifteen_free;
    }

    @Override
    protected void initView() {
        setStyle(0,R.style.QMUI_TipDialog);
    }

    @Override
    public void onStart() {
        super.onStart();
        Window win = getDialog().getWindow();
        DisplayMetrics dm = new DisplayMetrics();
        // 一定要设置Background，如果不设置，window属性设置无效
        if (win != null) {
            win.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
////            win.setLayout((dm.widthPixels), (int) (dm.heightPixels * 0.5));
            WindowManager.LayoutParams params = win.getAttributes();
//            params.dimAmount =  0.5f;
            params.windowAnimations = R.style.top_and_center_animation;
            win.setAttributes(params);
//            // 使用ViewGroup.LayoutParams，以便Dialog 宽度充满整个屏幕
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.setUserActivityState();
        PreferenceUtil.getInstance(mActivity).setNeverShowFifteenDaysDialogState();
    }

    @OnClick({R.id.iv_dismiss, R.id.tv_join_in})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_dismiss:
                break;
            case R.id.tv_join_in:
                FreeBookActivity.start(mActivity);
//                if (UserInstance.getUser().isLogin()) {
//
//                } else {
//                   DialogManager.showLoginDialog()
//                }
                break;
        }
        dismiss();
    }

    @Override
    public void initData() {

    }

    @Override
    public void showContent() {

    }

    @Override
    public void showProgress() {

    }

    @Override
    public void showError(Throwable throwable) {

    }

    @Override
    public void showEmpty() {

    }
}
